import type {BusData} from "../../types/DataTypes";
import {BusDAO} from "../../DAO";

export class BusService {
    // ==================== 巴士操作 ====================

    // 新增巴士
    static async addBus(bus: BusData): Promise<boolean> {
        return BusDAO.addBus(bus);
    }

    // 批量新增巴士
    static async addBuses(buses: BusData[]): Promise<number> {
        return BusDAO.addBuses(buses);
    }

    // 获取所有巴士
    static async getAllBuses(): Promise<BusData[]> {
        return BusDAO.getAllBuses();
    }

    // 根据位置模糊查询巴士
    static async searchBusesByLocation(keyword: string): Promise<BusData[]> {
        return BusDAO.searchBusesByLocation(keyword);
    }

    // 更新巴士数据
    static async updateBus(busData: BusData): Promise<boolean> {
        return BusDAO.updateBus(busData);
    }

    // 可用数量+1
    static async incrementBusAvailability(location: string): Promise<boolean> {
        return await BusDAO.incrementBusAvailability(location);
    }

    // 可用数量-1
    static async decrementBusAvailability(location: string): Promise<boolean> {
        return await BusDAO.decrementBusAvailability(location);
    }

    // 删除巴士
    static async deleteBus(location: string): Promise<boolean> {
        return BusDAO.deleteBus(location);
    }

    // 根据位置精确查询巴士
    static async getBusByLocation(location: string): Promise<BusData | null> {
        return BusDAO.getBusByLocation(location);
    }

    // 检查巴士是否存在
    static async busExists(location: string): Promise<boolean> {
        return BusDAO.busExists(location);
    }

    // 查询可用座位
    static async checkBusAvailability(location: string): Promise<boolean> {
        const bus = await BusDAO.getBusByLocation(location);
        return bus ? bus.availBus > 0 : false;
    }
}